package com.heixiu.gallery2

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.Transformations
import androidx.paging.toLiveData

class GalleryViewModel(application: Application) : AndroidViewModel(application) {
    private val factory = PixabayDataSourseFactory(application)
    val photoListLiveData = factory.toLiveData(10)
    val networkStatus = Transformations.switchMap(factory.pixabayLiveDataSourse) {it.networkStatus}

    fun resetData() {
        photoListLiveData.value?.dataSource?.invalidate()
    }

    fun retry() {
        factory.pixabayLiveDataSourse.value?.retry?.invoke()
    }
}
